home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / avalnche.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  146 lines

  1. /***************************************************************************
  2.  
  3. Atari Avalanche machine
  4.  
  5. If you have any questions about how this driver works, don't hesitate to
  6. ask.  - Mike Balfour (mab22@po.cwru.edu)
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int attract = 0;        /* Turns off sound in attract mode */
  13. static int volume = 0;        /* Volume of the noise signal */
  14. static int aud0 = 0;        /* Enable/disable noise */
  15. static int aud1 = 0;        /* Enable/disable 32V tone */
  16. static int aud2 = 0;        /* Enable/disable 8V tone */
  17. static int noise_k4=0;        /* First noise register */
  18. static int noise_l4=0;        /* Second noise register */
  19. static int noise=0;            /* Output noise signal */
  20.  
  21. /***************************************************************************
  22.   avalnche_input_r
  23. ***************************************************************************/
  24.  
  25. READ_HANDLER( avalnche_input_r )
  26. {
  27.     switch (offset & 0x03)
  28.     {
  29.         case 0x00:     return input_port_0_r(offset);
  30.         case 0x01:     return input_port_1_r(offset);
  31.         case 0x02:     return input_port_2_r(offset);
  32.         case 0x03:     return 0; /* Spare */
  33.     }
  34.     return 0;
  35. }
  36.  
  37. /***************************************************************************
  38.   avalnche_output_w
  39. ***************************************************************************/
  40.  
  41. WRITE_HANDLER( avalnche_output_w )
  42. {
  43.     switch (offset & 0x07)
  44.     {
  45.         case 0x00:        /* 1 CREDIT LAMP */
  46.             osd_led_w(0,(data & 0x01));
  47.             break;
  48.         case 0x01:        /* ATTRACT */
  49.             attract = data & 0x01;
  50.             break;
  51.         case 0x02:        /* VIDEO INVERT */
  52.             if (data & 0x01)
  53.             {
  54.                 palette_change_color(0,0,0,0);
  55.                 palette_change_color(1,255,255,255);
  56.             }
  57.             else
  58.             {
  59.                 palette_change_color(0,255,255,255);
  60.                 palette_change_color(1,0,0,0);
  61.             }
  62.             break;
  63.         case 0x03:        /* 2 CREDIT LAMP */
  64.             osd_led_w(1,(data & 0x01));
  65.             break;
  66.         case 0x04:        /* AUD0 */
  67.             aud0 = data & 0x01;
  68.             break;
  69.         case 0x05:        /* AUD1 */
  70.             aud1 = data & 0x01;
  71.             break;
  72.         case 0x06:        /* AUD2 */
  73.             aud2 = data & 0x01;
  74.             break;
  75.         case 0x07:        /* START LAMP (Serve button) */
  76.             osd_led_w(2,(data & 0x01));
  77.             break;
  78.     }
  79. }
  80.  
  81. /***************************************************************************
  82.   avalnche_noise_amplitude_w
  83. ***************************************************************************/
  84.  
  85. WRITE_HANDLER( avalnche_noise_amplitude_w )
  86. {
  87.     volume = data & 0x3F;
  88. }
  89.  
  90. /***************************************************************************
  91.   avalnche_interrupt
  92.  
  93.   Since all of the sound for this game is driven off of a vertical timer
  94.   signal, and our interrupts are driven off of a vertical timer signal,
  95.   we just handle generation of all of the sound signals inside of the
  96.   interrupt.  Note that the interrupt must occur twice as fast as the
  97.   fastest timer needed so that we can turn off sound on the "off" time.
  98. ***************************************************************************/
  99.  
  100. int avalnche_interrupt(void)
  101. {
  102.     static int time_8V  = 0;
  103.     static int time_16V = 0;
  104.     static int time_32V = 0;
  105.     int k4_input;
  106.     int l4_input;
  107.  
  108.     time_8V  = (time_8V  + 1) & 0x01;
  109.     time_16V = (time_16V + 1) & 0x03;
  110.     time_32V = (time_32V + 1) & 0x07;
  111.  
  112.     /* One audio tone is generated from an 8V clock */
  113.     if ((attract==0) && (aud2==1) && (time_8V==0))
  114.         DAC_data_w(0,255);
  115.     /* One audio tone is generated from a 32V clock */
  116.     else if ((attract==0) && (aud1==1) && (time_32V==0))
  117.         DAC_data_w(0,255);
  118.     else
  119.         DAC_data_w(0,0);
  120.  
  121.     /* Noise is driven by a 16V clock I think */
  122.     if ((attract==0) && (time_16V==0))
  123.     {
  124.         l4_input = 0x01 ^ ((noise_l4 & 0x01) ^ (((noise_k4) & 0x40) >> 6));
  125.         k4_input = (noise_l4 & 0x80) >> 7;
  126.  
  127.         noise_l4 = ((noise_l4 << 1) | l4_input) & 0xFF;
  128.         noise_k4 = ((noise_k4 << 1) | k4_input) & 0xFF;
  129.  
  130.         noise = (noise_k4 & 0x80) >> 7;
  131.     }
  132.  
  133.  
  134.     if ((aud0==0) && (noise))
  135.         DAC_data_w(1,volume);
  136.     else
  137.         DAC_data_w(1,0);
  138.  
  139.     /* Interrupt is generated by a 16V clock */
  140.     if (time_16V==0)
  141.         return nmi_interrupt();
  142.     else
  143.         return 0;
  144. }
  145.  
  146.